package com.haidechizi.mybatis.demo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * user
 *
 * @author haidechizi
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements RowMapper<User> {

    private Long id;
    private String userName;
    private String name;
    private Integer age;

    public User(Long id) {
        this.id = id;
    }

    @Override
    public User mapRow(ResultSet resultSet, int i) throws SQLException {
        User user = new User();
        user.setId(resultSet.getLong("id"));
        user.setUserName(resultSet.getString("user_name"));
        user.setName(resultSet.getString("name"));
        user.setAge(resultSet.getInt("age"));
        return user;
    }
}
